package com.example.demoviewlocaldata.controller;

import com.example.demoviewlocaldata.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.HashMap;

@Controller
public class TestController {
    @GetMapping("index")
    public String GetIndex(Model model){

        User user1 = new User("yang", 4, "duidui");
        User user2 = new User("y", 4, "bb");
        User user3 = new User("h", 4, "aa");

        ArrayList<User> userArrayList = new ArrayList<>();
        userArrayList.add(user2);
        userArrayList.add(user3);

        ArrayList<String> userList = new ArrayList<>();
        userList.add(" zhang san 66");

        HashMap<String, String> map = new HashMap<>();
        map.put("place","社湾");
        map.put("happy","yang");

        // 数据添加到model中
        // 普通字符串
        model.addAttribute("name","yang");

        // 储存JavaBean-对象
        model.addAttribute("user",user1);


        model.addAttribute("userArrayList",userArrayList);

        // 储存字符串List
        model.addAttribute("userList",userList);

        // 储存map
        model.addAttribute("map",map);

        return "index";  // 与templates中index.html对应
    }
}
